import request from '@/config/axios'

// 平台会员 VO
export interface MemberVO {
  id: number // ID
}

export interface TransferVO {
  fromPhone: number // ID
  toPhone: number // ID
  amount: number // ID
  type: number // ID
  busId: number // ID
}

// 平台会员 API
export const MemberApi = {
  // 查询平台会员分页
  getMemberPage: async (params: any) => {
    return await request.get({ url: `/wo/member/page`, params })
  },

  // 查询平台会员详情
  getMember: async (id: number) => {
    return await request.get({ url: `/wo/member/get?id=` + id })
  },

  // 查询平台会员详情
  getTeam: async (id: number, type: number, lv: number) => {
    return await request.get({ url: `/wo/member/get/team`, params: { id, type, lv } })
  },

  // 新增平台会员
  createMember: async (data: MemberVO) => {
    return await request.post({ url: `/wo/member/create`, data })
  },

  importMember: async (data: Array<number>) => {
    return await request.post({ url: `/wo/member/import`, data })
  },

  importTeam: async (file: File) => {
    return await request.post({
      url: `/wo/member/team/import`,
      data: {
        file: file
      },
      headersType: 'multipart/form-data'
    })
  },

  // 新增平台会员
  transferAccount: async (data: TransferVO) => {
    return await request.post({ url: `/wo/member/account`, data })
  },

  // 修改平台会员
  updateMember: async (data: MemberVO) => {
    return await request.put({ url: `/wo/member/update`, data })
  },

  // 删除平台会员
  deleteMember: async (id: number) => {
    return await request.delete({ url: `/wo/member/delete?id=` + id })
  },

  // 导出平台会员 Excel
  exportMember: async (params) => {
    return await request.download({ url: `/wo/member/export-excel`, params })
  },

  // ==================== 子表（会员关系） ====================

  // 获得会员关系
  getMemberTeamByMemberId: async (memberId) => {
    return await request.get({
      url: `/wo/member/member-team/get-by-member-id?memberId=` + memberId
    })
  },

  // ==================== 子表（账户） ====================

  // 获得账户列表
  getAccountListByMemberId: async (memberId) => {
    return await request.get({ url: `/wo/member/account/list-by-member-id?memberId=` + memberId })
  }
}
